<?php
define('KAIZEKU',1);
/**
 * WP-iStalker Chrome Min 
 * Filters function
 * 
 * @package	WordPress
 * @subpackage	wp-istalker-chrome-min
 * 
 * @category	HookAndFilters
 * @author	Avice (ChaosKaizer) De'vereux <ck+wp-istalker-min@istalker.net>
 * @author	NH. Noah <noah+wp-istalker-min@kakkoi.net>
 * @copyright 	2007 - 2009 Avice De'vereux, NH. Noah
 * @license 	http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License v2 
 * @version 	CVS: $Id: filters.php 13 2009-01-11 15:22:40Z chaoskaizer $
 * @since 	0.1
 */	



/**
 * void wpi_default_filters()
 * filter init
 * @see WpiMin::__construct()
 * @since 0.1
 */
function wpi_default_filters(){
	global $wp_styles;
		
	// rewrite rules			
		add_filter('query_vars','wpi_register_public_variables');
	 	add_action('template_redirect','wpi_process_query_var');
	 	add_action('init','wpi_flush_rewrite_rules'); 
		add_action('generate_rewrite_rules','wpi_add_rewrite_rules');
	
	// Stylesheets	
	add_filter('style_loader_tag','wpi_styles_style_loader_filter',10,2);	
	
	// Template
	add_filter(wpiFilter::DOCTYPE,'wpi_dtd_filter',2,1);
	
	// Plugins
	if (wpi_is_plugin_active('wp-pagenavi/wp-pagenavi.php')){
		remove_action('wp_head','pagenavi_css');	
	}
	
	// Widgets	
}


/**
 * Null filter, use for disabling function
 * 
 * @since 0.1
 */
function wpi_null(){ return '';}


/**
 * wpi_styles_style_loader_filter()
 * check for compressed stylesheet and null it
 * 
 * filter: style_loader_tag (args 2)
 * @uses $wp_styles WP_Styles object
 * @since 0.1
 */
function wpi_style_loader_filter($tag, $handle){
	global $wp_styles;
	
	if (isset($wp_styles->registered[$handle]->deps['combine'])
		&& $wp_styles->registered[$handle]->deps['combine'] == true ){
			return '';
	} else {
		return $tag;	
	}
}


/**
 * wpi_script_loader_filter()
 * check for combine script and null it
 * 
 * filter: script_loader_tag (args 2)
 * @uses $wp_scripts WP_Scripts object
 * @since 0.1
 */
function wpi_script_loader_filter($tag, $handle){
	global $wp_scripts;
	
	if (isset($wp_scripts->registered[$handle]->deps['combine'])
		&& $wp_scripts->registered[$handle]->deps['combine'] == true ){
			return '';
	} else {
		return $tag;	
	}
}

/**
 * append xml doc style root if client
 * agent accept xml
 * accept arguments 1, string DTD
 * filter: wpiTheme::DOCTYPE
 * 
 * @category Filter
 * @see wpiTemplate::docType()
 * @uses get_bloginfo
 * @uses WPI_CLIENT_ACCEPT_XML 
 * @param string xhtml doctype
 * @since 0.1
 */
function wpi_dtd_filter($dtd){
	
	if (defined('WPI_CLIENT_ACCEPT_XML') && WPI_CLIENT_ACCEPT_XML){			
		$charset = get_bloginfo('charset');			
		$output = '<?xml version="1.0" encoding="'.$charset.'"?>'.PHP_EOL;
	}
	
	return $output.$dtd;	
}


/**
 * void wpi_register_public_variables()
 * Register query public variables
 * filter: query_vars
 * 
 * @category Filter
 * @param mixed|array $query public redirect query 
 * @since 0.1
 */
function wpi_register_public_variables($query){
	
	$query[] = wpiTheme::PUB_QUERY_VAR;
	
	return $query;	
}


/**
 * void wpi_flush_rewrite_rules()
 * Remove and recreate new set of rules
 * action filter: init
 * 
 * @category FilterAction
 * @uses $wp_rewrite WP_Rewrite object
 * @see WP_Rewrite::wp_rewrite_rules()
 * @since 0.1
 */
function wpi_flush_rewrite_rules(){
	global $wp_rewrite;
	$wp_rewrite->flush_rules();
}


/**
 * wpi_add_rewrite_rules()
 * Add theme's redirect query rules
 * action filter: generate_rewrite_rules
 * 
 * @category FilterAction
 * @uses $wp_rewrite WP_Rewrite object
 * @see WP_Rewrite::wp_rewrite_rules()
 * @since 0.1
 */
function wpi_add_rewrite_rules($wp_rewrite){
	
	if (is_object($wp_rewrite) && is_a($wp_rewrite,'WP_Rewrite')){
	  $new_rules = array(wpiTheme::PUB_QUERY_VAR.'/(.+)' 
	  				=>'index.php?'.wpiTheme::PUB_QUERY_VAR.'='.$wp_rewrite->preg_index(1));	
	  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;		
	}
}


/**
 * wpi_process_query_var()
 * Process query var
 * filter: template_redirect
 * 
 * @category FilterAction
 * @since 0.1
 */
function wpi_process_query_var($pub_var){
	
	if ( ($pub_var = get_query_var(wpiTheme::PUB_QUERY_VAR)) != false ){
		global $Wpi;
		
		// we used hash instead of generic name 
		switch ($pub_var){
			case '84cf6b85efd0f17750fa96c18e56a961': // wpiTemplate::docNav()				
				$Wpi->Template->docNav();
			break;		
		}		
		exit();
 	} 	
}                                                                                                            
?>